package com.horsen.service.edu.controller.admin;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.horsen.common.util.R;
import com.horsen.service.edu.controller.BaseController;
import com.horsen.service.edu.model.Video;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/**
 * 视频 控制器
 *
 * @author Horsen
 */
@Api(tags = "视频管理")
@ApiSupport(order = 6)
@RestController
@RequestMapping("/admin/edu/videos")
public class VideoController extends BaseController {

    @ApiOperationSupport(order = 1)
    @ApiOperation("根据ID获取一个视频")
    @GetMapping("/{id}")
    public R queryInfoById(@ApiParam(value = "课程ID", required = true)
                           @PathVariable String id) {
        Video video = videoService.getById(id);
        return video != null ?
                R.ok("获取ID=" + id + "的视频成功").setData("item", video) : R.error("获取ID=" + id + "的视频失败");
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("新增一个视频")
    @PostMapping("/")
    public R insert(@ApiParam(value = "视频对象", required = true)
                    @RequestBody Video video) {
        return videoService.save(video) ?
                R.ok("新增视频成功") : R.error("新增视频失败");
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("修改一个视频")
    @PutMapping("/")
    public R update(@ApiParam("视频对象")
                    @RequestBody Video video) {
        return videoService.updateById(video) ?
                R.ok("修改视频成功") : R.error("修改视频失败");
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("根据ID删除视频")
    @DeleteMapping("/{id}")
    public R deleteById(@ApiParam(value = "视频ID", required = true)
                        @PathVariable String id) {
        return videoService.removeById(id) ?
                R.ok("删除ID=" + id + "的视频成功") : R.error("删除ID=" + id + "的视频失败");
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("获取视频数")
    @GetMapping("/count")
    public R count() {
        Integer count = videoService.countVideo();
        return R.ok("获取视频数成功").setData("count",count);
    }
}
